import * as types from './action-types';

function routerMiddleware(history) {
    return function(middlewareAPI) { // {getState, dispatch}
        return function(next) {
            return function(action) {
                if (action.type !== types.CALL_HISTORY_METHOD) {
                    return next(action);
                }
                // 拿到push.js中的action
                const { payload: { method, args }} = action;
                // 路径跳转
                history[method](...args);
            }
        }
    }
}

export default routerMiddleware;